
******************************************************************************
* GEORGIA **********
******************************************************************************

clear
cd "/Users/noahbuckley/Dropbox/Cooperating/Data/EAS replication files/"
use "EAS Georgia raw data.dta"

rename t9_dr str_t9_dr
recode d* (99=.)

gen t1var=1 if !missing(t1_1)
replace t1var=2 if !missing(t1_2)
replace t1var=3 if !missing(t1_3)
replace t1var=4 if !missing(t1_4)
*drop t1_*

gen t2var=1 if !missing(t2_1)
replace t2var=2 if !missing(t2_2)
replace t2var=3 if !missing(t2_3)
replace t2var=4 if !missing(t2_4)
*drop t2_*

gen t3var=1 if !missing(t3_1)
replace t3var=2 if !missing(t3_2)
replace t3var=3 if !missing(t3_3)
replace t3var=4 if !missing(t3_4)
*drop t3_*

gen t4var=1 if !missing(t4_1)
replace t4var=2 if !missing(t4_2)
replace t4var=3 if !missing(t4_3)
replace t4var=4 if !missing(t4_4)
*drop t4_*

gen t5var=1 if !missing(t5_1)
replace t5var=2 if !missing(t5_2)
replace t5var=3 if !missing(t5_3)
*drop t5_*

gen t6var=1 if !missing(t6_1)
replace t6var=2 if !missing(t6_2)
*drop t6_*

gen t7var=1 if !missing(t7_1)
replace t7var=2 if !missing(t7_2)
replace t7var=3 if !missing(t7_3)
replace t7var=4 if !missing(t7_4)
*drop t7_*
replace t7=6-t7

recode t1* t2* t3* t4* t5* t6* t7* t8* t9* (99=.)
recode t7* (-93=.)

replace t8_1=6-t8_1
replace t8_2=6-t8_2
replace t8_3=6-t8_3
replace t8_4=6-t8_4
replace t8_5=6-t8_5
replace t8_6=6-t8_6
replace t8_7=6-t8_7
replace t8_8=6-t8_8
replace t8_9=6-t8_9
replace t8_10=6-t8_10

replace t11=6-t11

* there's something funky with t7 and t8 in the data and in the excel (weighted?)

rename fio_int interviewer_name
rename cod_int interviewer_code
tab interviewer_code, gen(intv_dum_)

* better to build it ourselves
gen tbilisi=1 if reg==1
replace tbilisi=0 if tbilisi==.
recode reg (1/23=1)(24/33=0), gen(urban)



gen educ=d3
gen edu=educ
gen income=d10
gen age=d2
gen male=d1
recode male (2=0)
gen georgian=1 if d13==5
replace georgian=0 if d13!=5 & !missing(d13)
gen married=1 if d6==1
replace married=0 if d6!=1 & !missing(d6)
gen hh_size=d7
gen unemployed=1 if d4==11
replace unemployed=0 if d4!=11 & !missing(d4)

gen income_cat2=d9 								// check!
gen crimein12mo=1 if t14==1 | t15==1
replace crimein12mo=0 if crimein12mo==.
gen polstaknow=t10
recode polstaknow (2=0)
recode t12 (1 2=1)(3 4 5 6 7=0), gen(often_drive)
recode unemployed (0=1)(1=0), gen(working_respondent)
gen familysize=hh_size

recode t9_1 (98=.)							// what is 97? NR?
gen t9_sum=1 if t9_1!=97 & !missing(t9_1)
replace t9_sum=2 if t9_2!=97 & !missing(t9_2)
replace t9_sum=3 if t9_3!=97 & !missing(t9_3)
replace t9_sum=4 if t9_4!=97 & !missing(t9_4)
replace t9_sum=5 if t9_5!=97 & !missing(t9_5)
replace t9_sum=0 if t9_1==97

gen contact_any=t9_sum
recode contact_any (2 3 4 5=1), gen(contact_any_binary)

rename contact_any contact_any_count
rename contact_any_binary contact_any

gen trust_police=t8_2
gen trust_govt=t8_6
gen satis_police=t11

gen region=reg
tab region, gen(regiondum_)

*save "~/Dropbox/Cooperating/Data/Georgia survey 2013/Georgia survey data.dta", replace

******************
* switch and rename things to match Russia survey data

* Duty/reward: t1 -> q3			(var order good for final)
gen full3=t1
gen q3var=t1var

* Anonymity: t2 -> q6			(var order good for final)
gen full6=t2
gen q6var=t2var

* Value/time: t3 -> q2			(var order good for final)
gen full2b=t3
gen q2bvar=t3var

* Policeman/beating: t4 -> q1 	(var order good for final)
gen full1b=t4
gen q1bvar=t4var

recode full1b (.=1)(1/5=0), gen(q1bmiss)
recode full2b (.=1)(1/5=0), gen(q2bmiss)
recode full6 (.=1)(1/5=0), gen(q6miss)
recode full3 (.=1)(1/5=0), gen(q3miss)
gen missing=q1bmiss+q2bmiss+q6miss+q3miss
gen missingrate=missing/4

recode q1bvar (1 2 = 1)(3 4=0), gen(police)
recode q1bvar (4 2 = 1)(3 1=0), gen(beating)
gen policeXbeating=police*beating
recode q3var (4 2 = 1)(3 1=0), gen(duty)
recode q3var (1 2 = 0)(3 4=1), gen(reward)
gen dutyXreward=duty*reward
recode q2bvar (4 2 = 1)(3 1=0), gen(busy)
recode q2bvar (1 2 = 0)(3 4=1), gen(highval)
gen busyXhighval=busy*highval
recode q6var (4 2=0)(3 1=1), gen(anonymous)
recode q6var (1 2=1)(3 4=0), gen(q6police)
gen anonXq6police=anonymous*q6police

gen beatingXbusy=beating*busy
gen beatingXhighval=beating*highval
gen beatingXbusyXhighval=beating*busy*highval

gen beatingXduty=beating*duty
gen beatingXreward=beating*reward
gen beatingXdutyXreward=beating*duty*reward

replace age=age/100

gen material=income_cat2							

gen policeXtrust=police*trust_police
gen beatingXtrust=beating*trust_police
gen dutyXtrust=duty*trust_police
gen rewardXtrust=reward*trust_police
gen busyXtrust=busy*trust_police
gen highvalXtrust=highval*trust_police

gen policeXgovt=police*trust_govt
gen beatingXgovt=beating*trust_govt
gen dutyXgovt=duty*trust_govt
gen rewardXgovt=reward*trust_govt
gen busyXgovt=busy*trust_govt
gen highvalXgovt=highval*trust_govt

saveold "EAS Georgia prepared data.dta", replace


******************************************************************************
* RUSSIA **********
******************************************************************************

clear
cd "/Users/noahbuckley/Dropbox/Cooperating/Data/EAS replication files/"
use "EAS Russia raw data.dta"  // == Police Survey 2012.dta	

gen y1=qt5_1
replace y1=qt5_2 if y1==.
gen y2=qt5_1
replace y2=qt5_3 if y2==.

label variable y1 "Response for Q5 treatment 1"
label variable y2 "Response for Q5 treatment 2"

gen treat1=qt5_1
recode treat1 (1 2 3 4=0)
replace treat1=1 if qt5_2!=.

label variable treat1 "Treatment indicator for Q5 treatment 1"

gen treat2=qt5_1
recode treat2 (1 2 3 4=0)
replace treat2=1 if qt5_3!=.

label variable treat2 "Treatment indicator for Q5 treatment 2"

gen age=qs2
gen gender=qs1
recode gender (2=0), gen(male)
gen income_cat=qd9
recode qd10 (5=1)(4=2)(2=4)(1=5), gen(income_cat2)
gen income_cat3=qd8
replace income_cat2=3.5 if income_cat2==.   // NA here, need to fix...
gen worktype_breadwin=qd5b
gen worktype_respond=qd5a
recode qd5b (1 2 3 4 5 6=1)(7 8 9 10 11=0), gen(working_breadwin)
recode qd5a (1 2 3 4 5 6=1)(7 8 9 10 11=0), gen(working_respondent)
recode qd6 (3 4 5 6=1)(1 2=0), gen(livealone)
gen familysize=qd7a
gen educ=qs3
gen edu=educ

recode qu_r (2=0), gen(urban)
recode qrnp_zak (2 3 4 5 6 7=0), gen(moscow)
gen localpopulation=qrnp_zak
gen oblast=qobl
gen fedokrug=qfo

gen stratum=qto

gen trust_army=qt8_a
gen trust_police=qt8_b
gen trust_fsb=qt8_c
gen trust_courts=qt8_d
gen trust_muniauth=qt8_e
gen trust_govt=qt8_f
gen trust_duma=qt8_g
gen trust_prokuror=qt8_h
gen trust_church=qt8_i
gen trust_un=qt8_j

gen often_drive=7-qt12
recode qt13 (2=0), gen(gibdd_stop)
replace gibdd_stop=0 if gibdd_stop==.
recode qt14 (2=0), gen(victim_nonviolent)
recode qt15 (2=0), gen(victim_violent)
replace victim_violent=0 if victim_violent==.
replace victim_nonviolent=0 if victim_nonviolent==.
gen victim_any=victim_nonviolent
replace victim_any=1 if victim_violent==1
gen crimein12mo=victim_any

gen contact_called=qt9_1
gen contact_witness=qt9_2
gen contact_complaint=qt9_3
gen contact_doccheck_street=qt9_4
gen contact_doccheck_road=qt9_5
gen contact_interrog=qt9_6
gen contact_arrested=qt9_7
gen contact_inspector=qt9_8
gen contact_informal=qt9_9
gen contact_docform=qt9_10
gen contact_other=qt9_11
gen contact_nocontact=qt9_12
gen contact_gibdd=contact_doccheck_road
replace contact_gibdd=1 if gibdd_stop==1
replace contact_doccheck_road=1 if gibdd_stop==1

gen contact_active=contact_called
replace contact_active=1 if contact_complaint==1
replace contact_active=1 if contact_informal==1
replace contact_active=1 if contact_docform==1

gen contact_any=qt9_1+qt9_2+qt9_3+qt9_4+qt9_5+qt9_6+qt9_7+qt9_8+qt9_9+qt9_10+qt9_11
recode contact_any (2 3 4 5 6 7 8 9 10 11=1), gen(contact_any_binary)
replace contact_any_binary=1 if gibdd_stop==1

gen contact_relevant=qt9_1+qt9_3+qt9_4+qt9_5+qt9_6+qt9_7+qt9_8+qt9_10
recode contact_relevant (2 3 4 5 6 7 8=1), gen(contact_relevant_binary)
replace contact_relevant_binary=1 if gibdd_stop==1

recode trust_* (9=.)(1=5)(2=4)(4=2)(5=1)
recode often_drive (9=.)(1=7)(2=6)(3=5)(7=1)(6=2)(5=3)


recode qt10 (2=0), gen(polstaknow)
replace polstaknow=0 if polstaknow==.
recode qt11 (5=1)(4=2)(2=4)(1=5)(6=.), gen(satis_police)
gen howpolicework=satis_police


* make some categorical variables
recode age (18/25 = 1) (26/35 = 2) (36/45 = 3) (46/55 = 4) (56/65 = 5) (66/88 = 6), gen(age_cat)
recode age (18/25 = 1) (26/35 = 2) (36/55 = 3) (56/88 = 4), gen(age_cat_four)
recode age (18/21 = 1) (22/26 = 2) (27/31 = 3) (32/40 = 4) (41/49 = 5) (50/58 = 6) (59/67 = 7) (68/88 = 8), gen(age_cat_eight)
recode educ (1 2 = 1) (3 4 = 2) (5 6 = 3) (7 8 = 4), gen(educ_four)
recode income_cat2 (3.5 4 5=3), gen(income_cat2_three)
recode income_cat3 (1 2 = 1) (3=2) (4 5 6 =3), gen(income_cat3_three)

*** set up survey experiment variables
gen full1=qt1_1
replace full1=qt1_2 if full1==.
replace full1=qt1_3 if full1==.
replace full1=qt1_4 if full1==.
recode full1 (9=.)
gen q1var=1 if !missing(qt1_1)
replace q1var=2 if !missing(qt1_2)
replace q1var=3 if !missing(qt1_3)
replace q1var=4 if !missing(qt1_4)

gen full2=qt2_1
replace full2=qt2_2 if full2==.
replace full2=qt2_3 if full2==.
replace full2=qt2_4 if full2==.
recode full2 (9=.)
gen q2var=1 if !missing(qt2_1)
replace q2var=2 if !missing(qt2_2)
replace q2var=3 if !missing(qt2_3)
replace q2var=4 if !missing(qt2_4)

gen full3=qt3_1
replace full3=qt3_2 if full3==.
replace full3=qt3_3 if full3==.
replace full3=qt3_4 if full3==.
recode full3 (9=.)
gen q3var=1 if !missing(qt3_1)
replace q3var=2 if !missing(qt3_2)
replace q3var=3 if !missing(qt3_3)
replace q3var=4 if !missing(qt3_4)

gen full4=qt4_1
replace full4=qt4_2 if full4==.
replace full4=qt4_3 if full4==.
replace full4=qt4_4 if full4==.
recode full4 (9=.)
gen q4var=1 if !missing(qt4_1)
replace q4var=2 if !missing(qt4_2)
replace q4var=3 if !missing(qt4_3)
replace q4var=4 if !missing(qt4_4)

* rename survey expr variables to match previous survey
rename full4 full1b
rename q4var q1bvar

rename full3 full2b
rename q3var q2bvar

rename full1 full3
rename q1var q3var

rename full2 full6
rename q2var q6var


*save "/Users/noah/Dropbox/Cooperating/Data/Police survey 2012/Police Survey 2012 cleaned Feb2013.dta", replace

*clear
*cd "/Users/noahbuckley/Dropbox/Cooperating/Data/EAS replication files/"
*use "EAS Russia medium rare data.dta"

recode q1bvar (1 2 = 1)(3 4=0), gen(police)
recode q1bvar (4 2 = 1)(3 1=0), gen(beating)
gen policeXbeating=police*beating
recode q3var (4 2 = 1)(3 1=0), gen(duty)
recode q3var (1 2 = 0)(3 4=1), gen(reward)
gen dutyXreward=duty*reward
recode q2bvar (4 2 = 1)(3 1=0), gen(busy)
recode q2bvar (1 2 = 0)(3 4=1), gen(highval)
gen busyXhighval=busy*highval
recode q6var (4 2=0)(3 1=1), gen(anonymous)
recode q6var (1 2=1)(3 4=0), gen(q6police)
gen anonXq6police=anonymous*q6police

gen beatingXbusy=beating*busy
gen beatingXhighval=beating*highval
gen beatingXbusyXhighval=beating*busy*highval

gen beatingXduty=beating*duty
gen beatingXreward=beating*reward
gen beatingXdutyXreward=beating*duty*reward

gen material=income_cat2
rename contact_any contact_any_count
rename contact_any_binary contact_any

gen policeXtrust=police*trust_police
gen beatingXtrust=beating*trust_police
gen dutyXtrust=duty*trust_police
gen rewardXtrust=reward*trust_police
gen busyXtrust=busy*trust_police
gen highvalXtrust=highval*trust_police

gen policeXgovt=police*trust_govt
gen beatingXgovt=beating*trust_govt
gen dutyXgovt=duty*trust_govt
gen rewardXgovt=reward*trust_govt
gen busyXgovt=busy*trust_govt
gen highvalXgovt=highval*trust_govt

replace age=age/100

saveold "EAS Russia prepared data.dta", replace

******************************************************************************
* MERGED **********
******************************************************************************

append using "EAS Georgia prepared data.dta", generate(georgia)

gen policeXgeorgia=police*georgia
gen beatingXgeorgia=beating*georgia
gen policeXbeatingXgeorgia=police*beating*georgia
gen dutyXgeorgia=duty*georgia
gen rewardXgeorgia=reward*georgia
gen dutyXrewardXgeorgia=duty*reward*georgia
gen busyXgeorgia=busy*georgia
gen highvalXgeorgia=highval*georgia
gen busyXhighvalXgeorgia=busy*highval*georgia
gen anonymousXgeorgia=anonymous*georgia
gen q6policeXgeorgia=q6police*georgia
gen anonXq6policeXgeorgia=anonymous*q6police*georgia

gen ageXgeorgia=age*georgia
gen maleXgeorgia=male*georgia
gen eduXgeorgia=edu*georgia
gen materialXgeorgia=material*georgia
gen contact_anyXgeorgia=contact_any*georgia
gen crimein12moXgeorgia=crimein12mo*georgia
gen polstaknowXgeorgia=polstaknow*georgia
gen often_driveXgeorgia=often_drive*georgia
gen working_respondentXgeorgia=working_respondent*georgia
gen familysizeXgeorgia=familysize*georgia
gen urbanXgeorgia=urban*georgia

saveold "EAS merged prepared data.dta", replace
